package com.example.safeassistan.main;

import android.os.Build;

import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;

import com.example.safeassistan.hiddendanger.index.HiddenDangerIndex;
import com.example.safeassistan.home.index.HomeIndex;
import com.example.safeassistan.my.index.MyIndex;
import com.example.safeassistan.risk.index.RiskIndex;
import com.example.safeassistan.train.index.TrainIndex;

import java.util.ArrayList;
import java.util.List;

@RequiresApi(api = Build.VERSION_CODES.M)
public class MainPageController {
    private MainActivity context;
    private NoScrollViewPager vpContent;
    private List<Fragment> fragments;

    public MainPageController(MainActivity context, NoScrollViewPager vp) {
        this.context = context;
        this.vpContent = vp;
        fragments = new ArrayList<>();
        initViews();
    }

    private void initViews() {
        fragments.add(HomeIndex.newInstance("首页"));
        fragments.add(RiskIndex.newInstance("风险点"));
        fragments.add(HiddenDangerIndex.newInstance("隐患"));
        fragments.add(TrainIndex.newInstance("培训"));
        fragments.add(MyIndex.newInstance("我的"));
        MainPageAdapter mAdapter = new MainPageAdapter(context.getSupportFragmentManager(), fragments);
        //设置当前可见Item左右可见page数，次范围内不会被销毁
        vpContent.setOffscreenPageLimit(7);
        vpContent.setAdapter(mAdapter);
    }

    public void ChangePage(int position) {
        vpContent.setCurrentItem(position);
    }

}
